package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 游记
 */
@Getter@Setter
@JsonIgnoreProperties("json")
public class Travel extends BaseDomain{
    public static final Integer STATE_RELEASE = 2;//已发布
    public static final Integer STATE_AUDIT = 0;//草稿
    public static final Integer STATE_COMMON = 1;//待审核
    public static final Integer STATE_REJECT = -1;//拒绝


    //标题
    private String title;
    //旅行时间
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    //人均费用
    private String perExpends;
    //旅行时间
    private Integer days;
    //旅行人员
    private Integer person=6;
    //游记作者
    private User author;
    //创建时间
    @JsonFormat(pattern="yyyy-MM-dd  HH-mm-ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //发布时间
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date releaseTime;
    //游记是否公开
    private Boolean isPublic;
    //旅游地点
    private Region place;
    //游记封面url
    private String coverUrl;
    //游记最后更新时间
    //@JsonFormat将时间的返回JSON对象指定格式
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date lastUpdateTime;
    //状态
    private Integer state = STATE_RELEASE;
    //游记内容
    private TravelContent travelContent;

    //游记评论的数量
    private Long tarvelCommentNum;

    //该游记的点赞数
    private int doGoodNum;

    //根据其值,来返回对应的字符串表现形式
    public String getStateName(){
        String msg = "草稿";
        if(STATE_RELEASE==state){
            msg = "已发布";
        }else if(STATE_COMMON ==state){
            msg = "待审核";
        }else if(STATE_REJECT == state){
            msg = "拒绝";
        }
        return msg;
    }
    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("authorId",author.getId());
        return JSONUtil.toJSONString(map);
    }
    public String getPersonName(){
        String temp = "和其他";
        if (person==1) {
            temp = "一个人的旅行";
        }else if (person==2) {
            temp = "和父母";
        }else if (person==3) {
            temp = "和朋友";
        }else if (person==4) {
            temp = "和同事";
        }else if (person==5) {
            temp = "和爱人";
        }
        return temp;
    }
}